package com.songlanyun.modules.freighttemplate.controller.admin;

import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.freighttemplate.entity.FreightTemplate;
import com.songlanyun.modules.freighttemplate.entity.FreightTemplateRule;
import com.songlanyun.modules.freighttemplate.model.dto.FreightTemplateDTO;
import com.songlanyun.modules.freighttemplate.model.dto.FreightTemplateRuleDTO;
import com.songlanyun.modules.freighttemplate.service.FreightTemplateRuleService;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//import org.apache.shiro.authz.annotation.RequiresPermissions;



/**
 * 商家的物流模板的规则表（有一条默认规则，有其它与地区关联的特定规则表）
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-09 18:03:39
 */
@RestController
@RequestMapping("admin/freighttemplate/rule")
public class FreightTemplateRuleAdminController extends AbstractController {

    @Autowired
    private FreightTemplateRuleService freightTemplateRuleService;

    /**
     * 添加物流运费规则
     */
    @SysLog("添加物流运费规则")
    @PostMapping("/add/{templateId}")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:save")
    public R createRule(@PathVariable("templateId") Integer templateId,@RequestBody FreightTemplateRuleDTO dto){
        FreightTemplateRule obj = freightTemplateRuleService.createRule(getShopId(),templateId, dto);
        return R.ok().put("data",obj);
    }


    /**
     * 修改物流运费规则
     */
    @SysLog("修改物流运费规则")
    @PutMapping("/update/{templateId}")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:save")
    public R updateRule(@PathVariable("templateId") Integer templateId,@RequestBody FreightTemplateRuleDTO dto){
        FreightTemplateRule obj = freightTemplateRuleService.updateRule(getShopId(),templateId, dto);
        return R.ok().put("data",obj);
    }

    /**
     * 删除物流运费规则
     */
    @SysLog("删除物流运费规则")
    @DeleteMapping("/delete/{templateId}/{ruleId}")
    //@RequiresPermissions("freighttemplate:shopfreighttemplate:save")
    public R deleteRule(@PathVariable("templateId") Integer templateId,@PathVariable("ruleId") Integer ruleId){
        freightTemplateRuleService.deleteRule(getShopId(),templateId,ruleId);
        return R.ok();
    }

}
